// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;

    @property
    text: string = 'hello';

    @property(cc.Node)
    spshader: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.spshader.on(cc.Node.EventType.TOUCH_MOVE,this.touchMove, this);
    }


    start () {

    }

    // update (dt) {}

    setMatPro(x: number,y: number) {
        const spr = this.spshader.getComponent(cc.Sprite);
        const mat = spr.getMaterial(0);
        mat.setProperty('localCor',[x,y]);
    }

    touchMove(e: cc.Touch){
        let ed = e.getLocation();
        let l: cc.Vec2 = this.spshader.convertToNodeSpaceAR(ed);
        let lw = this.spshader.convertToWorldSpaceAR(l);
        let ld: cc.Vec2 = e.getLocationInView();
        let noco = this.spshader.getContentSize();
        let lc = cc.v2(ed.x, cc.winSize.height-ed.y);
        console.log('--e.getLocation ed--', ed);
        console.log('convertToNodeSpaceAR l', l);
        console.log('convertToWorldSpaceAR lc', lc);
        console.log('getLocationInView ld', ld);
        console.log('ed.x, cc.winSize.height-ed.y lw', lw);
        this.setMatPro(l.x,l.y);
        

    }
}
